package cn.lx.es.query.processor;

import cn.lx.es.query.annotation.PrefixSearch;
import cn.lx.es.query.annotation.SearchProcessor;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.lang.reflect.Field;

/**
 * 内置处理器 - 前缀搜索处理器
 */
@SearchProcessor
public class SearchPrefixProcessor implements SearchAnnotationProcessor<PrefixSearch> {
    @Override
    public void process(PrefixSearch annotation, Field field, Object value, BoolQueryBuilder boolQueryBuilder) {
        if (value != null) {
            boolQueryBuilder.must(QueryBuilders.prefixQuery(field.getName(), value.toString()));
        }
    }
    @Override
    public Class<PrefixSearch> getAnnotationType() {
        return PrefixSearch.class;
    }
}
